// packageRecruit/pages/create-post/create-post.js
import { positionSortList } from "../../api/recruit"
import user from "../../../utils/user.js"
Page({
    data: {
        terrIndex:0,
        hostId:'',
        list: [],
        childrenIndex:0,
        childrenId:'',
        repeatList:[]
    },
    onLoad: function (options) {
        user.waitLogin().then(res=>{
            this.getPositionSortList()
        })
    },
    onReady: function () {

    },
    onShow: function () {

    },
    getPositionSortList(){
        positionSortList({}).then(res=>{
            console.log(res,'res')
            this.setData({
                list:res,
                repeatList:res
            })
        })
    },
    onHostTree(event){
        const { id,index } = event.currentTarget.dataset
        this.setData({
            terrIndex:index,
            hostId:id
        })
    },
    async onChildrenTree(event){
        const { id,index,name } = event.currentTarget.dataset
        this.setData({
            childrenIndex:index,
            childrenId:id,
            hostId: this.data.hostId ? this.data.hostId : this.data.list[0].id
        })
        // /packageInsurance/pages/insurance-bill-detail/insurance-bill-detail?id='+event.currentTarget.dataset.id  
        wx.navigateTo({
            url: '/packageRecruit/pages/create-basic-info/create-basic-info?hostid=' + this.data.hostId + '&childrenid=' + this.data.childrenId + '&postname=' + name,
        })
    },
    search(event){
        if(event.detail.value.length == 0){
            this.setData({
                repeatList:this.data.list
            })
            return
        }
        const data = JSON.parse(JSON.stringify(this.data.list))
        const list = data.map((item,index)=>{
            item.children = item.children.filter((ite,ind)=>ite.name.includes(event.detail.value))
            return item
        }).filter(item => item.children.length)
        this.setData({
            repeatList:list
        })
    }
    // goBasicInfo(){
        
    // }
})